import { ConfigProvider } from 'antd'
import zhCN from 'antd/es/locale/zh_CN' // 导入 Ant Design 的中文语言包
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
import { ReactNode } from 'react'
import { ReactFlowProvider } from 'reactflow'
import { TooltipProvider } from '../components/ui/tooltip'
import { SSEProvider } from './SSEContext'
import { AlertProvider } from './alertContext'
import { DarkProvider } from './darkContext'
import { LocationProvider } from './locationContext'
import PopUpProvider from './popUpContext'
import { TabsProvider } from './tabsContext'
import { TypesProvider } from './typesContext'
import { UndoRedoProvider } from './undoRedoContext'
import { UserProvider } from './userContext'

dayjs.locale('zh-cn')

export default function ContextWrapper({ children }: { children: ReactNode }) {
  // element to wrap all context
  return (
    <>
      <TooltipProvider>
        <ReactFlowProvider>
          <DarkProvider>
            <TypesProvider>
              <LocationProvider>
                <AlertProvider>
                  <SSEProvider>
                    <TabsProvider>
                      <UndoRedoProvider>
                        <UserProvider>
                          <PopUpProvider>
                            <ConfigProvider locale={zhCN}>{children}</ConfigProvider>
                          </PopUpProvider>
                        </UserProvider>
                      </UndoRedoProvider>
                    </TabsProvider>
                  </SSEProvider>
                </AlertProvider>
              </LocationProvider>
            </TypesProvider>
          </DarkProvider>
        </ReactFlowProvider>
      </TooltipProvider>
    </>
  )
}
